package cn.icanci.ladybird.controller;

import cn.icanci.ladybird.service.util.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author: icanci
 * @date: Created in 2020/10/20 10:45
 * @classAction: ElasticSearchController
 */
@Controller
@RequestMapping("/api/v1/pri/search")
public class ElasticSearchController {
    @Autowired
    private ElasticSearchService elasticSearchService;

    @GetMapping("/init")
    @ResponseBody
    public Object init() throws Exception {
        return elasticSearchService.parseContent();
    }

    @GetMapping("/no-high")
    @ResponseBody
    public Object searchPageNoHigh(String keyword, int pageNo, int pageSize) throws Exception {
        List<Map<String, Object>> maps = elasticSearchService.searchPage(keyword, pageNo, pageSize);
        return maps;
    }

    @GetMapping("/high")
    @ResponseBody
    public Object searchPageHigh(String keyword, int pageNo, int pageSize) throws Exception {
        List<Map<String, Object>> maps = elasticSearchService.searchPageHigh(keyword, pageNo, pageSize);
        return maps;
    }
}
